package smartcarpool.smartspaceservice;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.Vector;

public class Triple implements Parcelable{

	private String subject;
	private String predicate;
	private String object;
    private String subject_type;
    private String object_type;

    /**
     * Create triple with default subject_type = "uri" and object_type = "literal"
     * @param subject
     * @param predicate
     * @param object
     */
	public Triple(String subject, String predicate, String object) {
		this.subject = subject;
		this.predicate = predicate;
		this.object = object;
        this.subject_type = "uri";
        this.object_type = "literal";
	}

    public Triple(String subject, String predicate, String object, String subject_type, String object_type) {
        this.subject = subject;
        this.predicate = predicate;
        this.object = object;
        this.subject_type = subject_type;
        this.object_type = object_type;
    }

    public Triple(Vector<String> tripleVector){
        //TODO: add check of vector size and elements?
        this.subject = tripleVector.elementAt(0);
        this.predicate = tripleVector.elementAt(1);
        this.object = tripleVector.elementAt(2);
        this.subject_type = tripleVector.elementAt(3);  // smart space returns subject_type, check sourceforge
        this.object_type = tripleVector.elementAt(4);
    }

    private Triple(Parcel parcel){
        this.subject = parcel.readString();
        this.predicate = parcel.readString();
        this.object = parcel.readString();
        this.subject_type = parcel.readString();
        this.object_type = parcel.readString();
    }

    @Override
	public int describeContents() {
		return 0;
	}

	public static final Creator<Triple> CREATOR
    = new Creator<Triple>() {
		public Triple createFromParcel(Parcel in) {
			return new Triple(in);
		}

		public Triple[] newArray(int size) {
			return new Triple[size];
		}
	};

	@Override
	public void writeToParcel(Parcel parcel, int arg1) {
		parcel.writeString(subject);
		parcel.writeString(predicate);
        parcel.writeString(object);
        parcel.writeString(subject_type);
        parcel.writeString(object_type);
	}

    public Vector toVector(){
        Vector<String> triple = new Vector<String>();
        triple.add(subject);
        triple.add(predicate);
        triple.add(object);
        triple.add(subject_type);
        triple.add(object_type);
        return triple;
    }
}
